//
//  JKCellFriends.m
//  chequanbao_ios
//
//  Created by 朱凯 on 2018/1/24.
//  Copyright © 2018年 com.itboye. All rights reserved.
//

#import "JKCellFriends.h"

#import "ByModelFriendAndRelative.h"

@implementation JKCellFriends
{
    UIImageView *_iconView;
    UILabel     *_nickLabel;
    UILabel     *_descLabel;
    UILabel     *_dateLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _iconView = [UIImageView new];
    _iconView.image = DEFAULT_IMAGE;
    _iconView.layer.cornerRadius = 25;
    _iconView.layer.masksToBounds = true;
    [self.contentView addSubview:_iconView];
    
    _nickLabel = [[UILabel alloc] init];
    _nickLabel.text = @"昵称";
    _nickLabel.font = FONT(16);
    _nickLabel.textAlignment = NSTextAlignmentLeft;
    _nickLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_nickLabel];
    
    _descLabel = [[UILabel alloc] init];
    _descLabel.text = @"描述描述描述";
    _descLabel.numberOfLines = 2;
    _descLabel.font = FONT(14);
    _descLabel.textAlignment = NSTextAlignmentLeft;
    _descLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_descLabel];
    
    _dateLabel = [[UILabel alloc] init];
    _dateLabel.text = @"时间";
    _dateLabel.font = FONT(14);
    _dateLabel.textAlignment = NSTextAlignmentRight;
    _dateLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_dateLabel];
    

    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
        make.width.height.equalTo(@50);
    }];
    [_nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(20);
        make.bottom.equalTo(_iconView.mas_centerY).offset(-2);
    }];
    [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nickLabel);
        make.top.equalTo(_iconView.mas_centerY).offset(2);
        make.right.equalTo(@-10);
        
        make.bottom.equalTo(@-15);
    }];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-10);
        make.top.equalTo(_nickLabel);
        make.left.greaterThanOrEqualTo(_nickLabel.mas_right).offset(10);
    }];
}
- (void)setModel:(ByModelFriendAndRelative *)model {
    
    _model = model;
    
    _nickLabel.text = model.nickname;
    [_iconView setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(model.head)] placeholderImage:DEFAULT_HEAD completed:nil];
    _dateLabel.text = [NSDate getDateForStringFotmatWithTimeInterval:[model.update_time doubleValue] formatter:@"yyyy.MM.dd"];
    _descLabel.text = model.sign.length == 0 ? @"无简介" : model.sign;
}
@end
